package com.easypan.controller;

import com.easypan.Service.FileShareService;
import com.easypan.annotation.GlobalInterceptor;
import com.easypan.entity.dto.SessionwebUserDto;
import com.easypan.entity.query.FileShareQuery;
import com.easypan.entity.vo.PaginationResultVO;
import com.easypan.entity.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/share")
public class fileshareController {
//    接口状态: 开发中
//    接口URL: POSThttp://localhost:7090/api/share/loadShareList
//    Content-Type: multipart/form-data
//    认证方式:无需认证

@Autowired
    FileShareService fileShareService;
    @PostMapping("/loadShareList")
    @GlobalInterceptor
    public R loadShareList(HttpSession session)
    {

        FileShareQuery fileShareQuer=new FileShareQuery();
        //根据ID 查询
        SessionwebUserDto sessionwebUserDto= (SessionwebUserDto) session.getAttribute("session_key");
        if(sessionwebUserDto==null){
            R.error("用户登录状态错误");
        }
        fileShareQuer.setUserId(String.valueOf(sessionwebUserDto.getUserId()));
        fileShareQuer.setQueryFileName(true);//进行关联查询
        PaginationResultVO paginationResultVO=fileShareService.findListByPage(fileShareQuer);
        return R.success(paginationResultVO);
    }
@PostMapping("/shareFile")
@GlobalInterceptor
        public   R shareFile(HttpSession session,
                            String fileId,
                             Integer validType,
                             String code)
{

    SessionwebUserDto sessionwebUserDto= (SessionwebUserDto) session.getAttribute("session_key");
    R r=fileShareService.shareFile(sessionwebUserDto,fileId,validType,code);
    return r;
}
@PostMapping("/cancelShare")
public  R cancelShare(String shareIds,HttpSession session)
{
//取消分享 可以传递多个值
    SessionwebUserDto sessionwebUserDto= (SessionwebUserDto) session.getAttribute("session_key");
  R r=  fileShareService.cancelShare(sessionwebUserDto,shareIds);
    return r;
}

////////////////外部分享

}
